package simulatorGUI;

import everything.Agent;
import everything.WorldMap;
import graphics.server.Boom;
import graphics.server.SingleAgent;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class DisplayWorld extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Boom bmain;
	public DisplayWorld(int[][] board, Agent a, int numRegions){
		super("Board");
		int Ysize = board.length;
		int Xsize = board[0].length;
		//create a frame for the crawler window applet
		bmain = new Boom();
		add(bmain,BorderLayout.CENTER);
		setSize(Xsize*46,Ysize*46);
		setLocation(20,200);
		bmain.init(Xsize,Ysize);
//		bmain.start();
		setVisible(true);
		setAlwaysOnTop(true);

		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		
		bmain.setAgent(new SingleAgent(a.getName(), a.getColor(), a.getDispOrientation(), getCellNumber(board, a.getX(), a.getY()), 46, 46));
//		System.out.print("Walls ");
		for (int i=0; i<board.length; i++){
			for (int j=0; j<board[i].length; j++){
				if (board[i][j] == WorldMap.WALL){
//					System.out.print(getCellNumber(board, i, j)+" ");
					bmain.setWall(getCellNumber(board, i, j));
				} else if (board[i][j] == WorldMap.FLAG){
					bmain.setFlag(getCellNumber(board, i, j));
				}
			}
		}
//		System.out.println();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	private int getCellNumber(int[][] _board, int x, int y){
		return (y+x*_board[0].length);
	}

	public void setProb(Integer key, double iceProb, double s1Prob, double s2Prob) {
		// TODO Auto-generated method stub
		bmain.setProb(key.intValue(), iceProb, s1Prob, s2Prob);
	}
}
